home *** CD-ROM | disk | FTP | other *** search
-
- /* @(#)get.c 1.3 91/11/13
- *
- * Various extraction routines used by reve.
- *
- * Copyright (C) 1990, 1991 - Rich Burridge & Yves Gallot.
- * All rights reserved.
- *
- * Permission is granted to copy this source, for redistribution
- * in source form only, provided the news headers in "substantially
- * unaltered format" are retained, the introductory messages are not
- * removed, and no monies are exchanged.
- *
- * Permission is also granted to copy this source, without the
- * news headers, for the purposes of making an executable copy by
- * means of compilation, provided that such copy will not be used
- * for the purposes of competition in any othello tournaments, without
- * prior permission from the authors.
- *
- * No responsibility is taken for any errors on inaccuracies inherent
- * either to the comments or the code of this program, but if reported
- * (see README file), then an attempt will be made to fix them.
- */
-
- #include "reve.h"
- #include "extern.h"
- #include <ctype.h>
-
-
- int
- get_bool_resource(rtype, boolval) /* Get boolean resource from the server. */
- enum res_type rtype ;
- int *boolval ;
- {
- char *val, tempstr[MAXLINE] ;
- int len, n ;
-
- if ((val = get_resource(rtype)) == NULL) return(0) ;
- STRCPY(tempstr, val) ;
- len = strlen(tempstr) ;
- for (n = 0; n < len; n++)
- if (isupper(tempstr[n])) tempstr[n] = tolower(tempstr[n]) ;
- if (EQUAL(tempstr, "true")) *boolval = TRUE ;
- else *boolval = FALSE ;
- return(1) ;
- }
-
-
- /* Search through the command line options to see if a -display <display>
- * has been given. We can't process the command line arguments first,
- * (using get_options()), because the SunView and XView versions, are
- * capable of having a lot of generic command line arguments which would
- * be a pain to handle. The init_graphics() routine will strip those off,
- * but the X11 version, needs the display name.
- */
-
- void
- get_display(argc, argv)
- int argc ;
- char *argv[] ;
- {
- INC ;
- while (argc > 0)
- {
- if (argv[0][0] == '-' && EQUAL(argv[0], "-display"))
- {
- INC ; /* X11 display information. */
- read_str(&display, *argv) ;
- return ;
- }
- INC ;
- }
- }
-
-
- int
- get_int_resource(rtype, intval) /* Get integer resource from the server. */
- enum res_type rtype ;
- int *intval ;
- {
- char *val ;
-
- if ((val = get_resource(rtype)) == NULL) return(0) ;
- *intval = atoi(val) ;
- return(1) ;
- }
-
-
- void
- get_options(argc, argv) /* Read and process command line options. */
- int argc ;
- char *argv[] ;
- {
- char next[MAXLINE] ; /* The next command line parameter. */
- int i ;
-
- INC ;
- while (argc > 0)
- {
- if (argv[0][0] == '-')
- switch (argv[0][1])
- {
- case 'a' : /* Allow computer glide and piece dragging. */
- if (EQUAL(argv[0], "-animate")) ANIMATION = TRUE ;
- break ;
- case 'b' : if (EQUAL(argv[0], "-bestmove")) DO_BESTMOVE = TRUE ;
- else if (EQUAL(argv[0], "-black")) isblack = 1 ;
- break ;
- case 'c' : if (EQUAL(argv[0], "-clock")) DO_CLOCK = TRUE ;
- break ;
- case 'd' : if (EQUAL(argv[0], "-debug")) debug = TRUE ;
- else if (EQUAL(argv[0], "-display"))
- {
- INC ; /* Already processed. */
- }
- else
- {
- INC ;
- getparam(next, argv, "-d needs difficulty") ;
- level = atoi(next) ;
- if (level < 1 || level > MAXDIFF)
- level = INIT_DEPTH ;
- items[(int) DIFF_CHOICE].value = level - 1 ;
- old_diffval = level-1 ;
- }
- break ;
- case 'e' : INC ;
- getparam(edgefile, argv, "-e needs an edgetable file") ;
- break ;
- case 'g' : INC ; /* X11 geometry information. */
- getparam(geometry, argv,
- "-g needs geometry information") ;
- break ;
- case 'h' : if (EQUAL(argv[0], "-help")) help_showing = TRUE ;
- else
- {
- INC ;
- getparam(helpfile, argv, "-h needs a help file") ;
- }
- break ;
- case 'i' : inv_video = 1 ; /* Display in inverse video. */
- break ;
- case 'l' : if (EQUAL(argv[0], "-last")) DO_LAST = TRUE ;
- else if (EQUAL(argv[0], "-log")) saveres = TRUE ;
- else if (EQUAL(argv[0], "-load"))
- {
- INC ; /* Reve game file to load. */
- getparam(gamefile, argv, "-l needs a game file") ;
- loadgame = 1 ; /* Game file to load. */
- }
- break ;
- case 'm' : monochrome = 1 ; /* Force display to mono. */
- iscolor = 0 ;
- break ;
- case 'n' : if (EQUAL(argv[0], "-notes")) SHOW_NOTES = TRUE ;
- else if (EQUAL(argv[0], "-number")) DO_NUMBER = TRUE ;
- break ;
- case 'o' : if (EQUAL(argv[0], "-opponent"))
- if (*(argv+1) != NULL && argv[1][0] != '-')
- {
- INC ;
- opponent = *argv ;
- play_computer = 0 ;
- }
- break ;
- case 'p' : if (EQUAL(argv[0], "-props")) props_showing = TRUE ;
- break ;
- case 'q' : if (EQUAL(argv[0], "-quick")) QUICKGAME = TRUE ;
- break ;
- case 'r' : INC ;
- getparam(reveproc, argv,
- "-r needs a reve_proc pathname") ;
- break ;
- case '?' :
- case 'v' : usage() ;
-
- case 'w' : if (EQUAL(argv[0], "-white")) iswhite = 1 ;
- break ;
-
- /* SunView windowing arguments. -Wp, -WP and -Wi are used in the X11
- * implementation to initially position the window and icon.
- */
-
- case 'W' : switch (argv[0][2])
- {
- case 'H' : break ; /* -WH, no sub-args follow */
- case 'i' : iconic = 1 ;
- break ; /* -Wi, start as an icon. */
- case 'g' : /* -Wg, set default color. */
- case 'n' : break ; /* -Wn, no label at all */
- case 'h' : /* -Wh, height */
- case 'I' : /* -WI "icon filename" */
- case 'l' : /* -Wl "some window label" */
- case 'L' : /* -Wl "some icon label" */
- case 't' : /* Font filename */
- case 'T' : /* Icon font filename */
- case 'w' : INC ; /* Width, in columns. */
- break ;
- case 'p' : INC ; /* -Wp xnum ynum */
- getparam(next, argv,
- "-Wp needs x coordinate") ;
- wx = atoi(next) ;
- INC ;
- getparam(next, argv,
- "-Wp needs y coordinate") ;
- wy = atoi(next) ;
- posspec = 1 ;
- break ;
- case 'P' : INC ; /* -WP xnum ynum */
- getparam(next, argv,
- "-WP needs x coordinate") ;
- ix = atoi(next) ;
- INC ;
- getparam(next, argv,
- "-WP needs y coordinate") ;
- iy = atoi(next) ;
- break ;
- case 's' : INC ; INC ; /* -Ws xnum ynum */
- break ;
- case 'b' : /* -Wb r g b (bg color spec)
- */
- case 'f' : INC ; INC ; INC ; /* Same, fg color */
- break ;
- default : FPRINTF(stderr,"%s: -W%c unknown argument\n",
- progname, argv[0][2]) ;
- break ;
- }
- break ;
- case 'x' : if (EQUAL(argv[0], "-xdebug")) xdebug = TRUE ;
- break ;
- default : usage() ;
- }
- INC ;
- }
- }
-
-
- int
- get_str_resource(rtype, strval) /* Get a string resource from the server. */
- enum res_type rtype ;
- char *strval ;
- {
- char *val ;
-
- if ((val = get_resource(rtype)) == NULL) return(0) ;
- STRCPY(strval, val) ;
- return(1) ;
- }
-
-
- void
- getparam(s, argv, errmes)
- char *s, *argv[], *errmes ;
- {
- if (*argv != NULL && argv[0][0] != '-') STRCPY(s, *argv) ;
- else
- {
- FPRINTF(stderr,"%s: %s as next argument.\n", progname, errmes) ;
- exit(1) ;
- }
- }
-
-
- char *
- getuserhost()
- {
- char namehost[MAXLINE], *name, host[MAXLINE] ;
- int len ;
-
- name = getlogin() ;
- if (name == NULL) name = "unknown" ;
- len = MAXLINE ;
- gethostname(host, &len) ;
- SPRINTF(namehost, "%s@%s", name, host) ;
- return(namehost) ;
- }
-